﻿using Castle.MicroKernel.Registration;
using Castle.Windsor;
using Twins.Classes;
using Twins.Classes.Hanlder;
using Twins.Classes.Processer;
using Twins.Interface;
using Twins.Interface.IProcesser;

namespace Twins.Infrastructure
{
    public class IoC
    {
        private static WindsorContainer windsorContainer;

        public static void Initialize()
        {
            windsorContainer = new WindsorContainer();
            windsorContainer.Register(Component.For<DispatherProject>());
            windsorContainer.Register(Component.For<ICodeExecutor>().ImplementedBy<CodeExecutor>());
            windsorContainer.Register(Component.For<ILookCSharpFile>().ImplementedBy<LookCSharpFile>());
            windsorContainer.Register(Component.For<ITwinsHighLighting>().ImplementedBy<TwinsHighLighting>());
            windsorContainer.Register(Component.For<ISelectorDuplicationHashsLineCodeFiles>()
                .ImplementedBy<SelectorDuplicationHashsLineCodeFiles>());
            windsorContainer.Register(Component.For<IAdderLineCode>().ImplementedBy<AdderLineCode>());
            windsorContainer.Register(Component.For<IProcesser>().ImplementedBy<ProcesserCSharpExpression>()
                .Named("ProcesserCSharpExpression"));
            windsorContainer.Register(Component.For<IProcesser>().ImplementedBy<ProcesserCSharpStatement>()
                .Named("ProcesserCSharpStatement"));
            windsorContainer.Register(Component.For<IReceiveHashLineCodeFromProcesserCSharpExpression>()
                .ImplementedBy<ReceiveHashLineCodeFromProcesserCSharpExpression>());
            windsorContainer.Register(Component.For<IReceiveHashLineCodeFromProcesserCSharpStatement>()
                .ImplementedBy<ReceiveHashLineCodeFromProcesserCSharpStatement>());
        }

        public static TService Resolve<TService>()
        {
            return windsorContainer.Resolve<TService>();
        }

        public static TService Resolve<TService>(string name)
        {
            return windsorContainer.Resolve<TService>(name);
        }
    }
}